const Controller = require('egg').Controller;

class AnnouncementController extends Controller {
  async create() {
    const { ctx } = this;
    const result = await this.service.announcement.create();
    ctx.body = { id: result.insertId };
  }

  async delete() {
    const { ctx } = this;
    await this.service.announcement.delete();
    ctx.body = { message: 'Deleted' };
  }

  async update() {
    const { ctx } = this;
    await this.service.announcement.update();
    ctx.body = { message: 'Updated' };
  }

  async list() {
    const { ctx } = this;
    const results = await this.service.announcement.list();
    ctx.body = { data: results };
  }
  
  async read() {
    const { ctx } = this;
    const result = await this.service.announcement.read();
    ctx.body = result;
  }
}

module.exports = AnnouncementController;
